package mylab.base.foundation.orm.ability;

import java.sql.SQLException;

import cn.hutool.db.Entity;
import mylab.base.foundation.lang.Identifiable;
import mylab.base.foundation.orm.EntityUtil;

public interface Update<T extends Identifiable<Long>> extends DS, EntityInfo<T> {

    default int updateById(T entity) throws SQLException {
        Entity record = Entity.parse(entity);
        Entity where = EntityUtil.where(getTableName());
        where.set("id", entity.getId());
        return update(record, where);
    }

    default int update(Entity record, Entity where) throws SQLException {
        return getDb().update(record, where);
    }
}
